package com.wljy.developtool.controller;

import com.wljy.developtool.service.INoticeService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Slf4j
@Controller
@RequestMapping(value = "/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    @GetMapping("/error")
    public ResponseEntity<Object> error(String message) {
        try {
            WxCpMessageSendResult res = noticeService.sendError(message);
            return ResponseEntity.ok(res);
        } catch (WxErrorException e) {
            log.error("WxError : {}", e);
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
        }
    }

    @GetMapping("/warn")
    public ResponseEntity<Object> warn(String message) {
        try {
            WxCpMessageSendResult res = noticeService.sendWarn(message);
            return ResponseEntity.ok(res);
        } catch (WxErrorException e) {
            log.error("WxError : {}", e);
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
        }
    }

    @GetMapping("/info")
    public ResponseEntity<Object> info(String message) {
        try {
            WxCpMessageSendResult res = noticeService.sendInfo(message);
            return ResponseEntity.ok(res);
        } catch (WxErrorException e) {
            log.error("WxError : {}", e);
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
        }
    }

}
